#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n,m;
char s[3000011];
int f[3000011][2];
int full[3000011];
int a[3000011],op[3000011];
int rop[3000011],rcnt[3000011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	while(cin >> s[++n]);
	n--;
	bool flag = 1;
	for(int i = 2;i <= n;i++) if(s[i] == s[i - 1])
		flag = 0;
	if(flag)
	{
		int cnt = 1;
		for(int i = 1;i < n;i++) if(s[i] == 'B')
			cnt++;
		cout << cnt << "\n";
		return 0;
	}
	for(int i = 1;i <= n;i++)
	{
		if(s[i] != s[i - 1])
			op[++m] = (s[i] - 'A');
		a[m]++;
	}
	op[0] = op[1] ^ 1;
	f[0][0] = 1;
	for(int i = 0;i < m;i++)
	{
		for(int o = 0;o < 2;o++)
		{
			int x = 1,y = 2;
			int rst = o,len = 0;
			for(int j = i + 1;j <= m;j++)
			{
				if(op[j] == op[i])
				{
					rst ^= (a[j] & 1);
					continue;
				}
				len += a[j];
				if(rst)
					len--,rst = 0;
				if((len & 1) || op[j] == 1)
					while(x <= len)
					{
						if(x == len)
							(full[j] += f[i][o]) %= mod;
						(f[j][(len - x) & 1] += f[i][o]) %= mod,x += 2;
					}
				if(((len & 1) ^ 1) || op[j] == 1)
					while(y <= len)
					{
						if(y == len)
							(full[j] += f[i][o]) %= mod;
						(f[j][(len - y) & 1] += f[i][o]) %= mod,y += 2;
					}
			}
		}
	}
	long long ans = 0;
	for(int i = 1;i <= m;i++)
	{
		long long w = 0;
		for(int o = 0;o < 2;o++)
			w += f[i][o];
		(ans += w) %= mod;
	}
	cout << ans;
	return 0;
}